﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace ServerManager.Data
{
    public partial interface IRepository<T> where T : class
    {
        /// <summary>
        /// Get entity by identifier
        /// </summary>
        /// <param name="id">Identifier</param>
        /// <returns>Entity</returns>
        T GetById(object id);

        T Find(Expression<Func<T, bool>> whereLambda);

        IEnumerable<T> FindAll(Expression<Func<T, bool>> whereLambda);

        Task<IEnumerable<T>> FindAllAsync(Expression<Func<T, bool>> whereLambda);

        T Add(T entity);

        Task<T> AddAsync(T entity);

        void Add(IEnumerable<T> entities);

        Task<IEnumerable<T>> AddAsync(IEnumerable<T> entities);

        int Update(T entity);

        Task<int> UpdateAsync(T entity);

        Task UpdateAsync(IEnumerable<T> entities);

        int Delete(Expression<Func<T, bool>> predicate);

        Task<int> DeleteAsync(Expression<Func<T, bool>> predicate);

        bool Exist(Expression<Func<T, bool>> anyLambda);

        int Count(Expression<Func<T, bool>> predicate);

        /// <summary>
        /// Gets a table
        /// </summary>
        IQueryable<T> Table { get; }

        /// <summary>
        /// Gets a table with "no tracking" enabled (EF feature) Use it only when you load record(s) only for read-only operations
        /// </summary>
        IQueryable<T> TableNoTracking { get; }

        ApplicationDbContext GetDbContext();
    }
}
